<?php
class Application_Model_Tags extends Application_Model_Db_Db
{
    /**
     * get the most used tags
     * @param int $countTags
     * @return array
     */
    public function getPopularTags($countTags=10) {
		$sql = "SELECT
					`tag`.`id`,
		            CONCAT(UPPER(LEFT(`tag`.`tag_name`, 1 )), LOWER(SUBSTRING(`tag`.`tag_name`,2))) AS `tag_name`,
		            COUNT(`content_tag`.`tag_id`) AS `cnt`
		        FROM `content_tag`
		        INNER JOIN `content`
		            ON `content_tag`.`content_id` = `content`.`id`
		        INNER JOIN `tag`
		            ON `content_tag`.`tag_id` = `tag`.`id`
		        GROUP BY `tag`.`tag_name`
		        ORDER BY `cnt` DESC
		        LIMIT 0, {$countTags}";
		return $this->_db->fetchAll($sql);
	}	
}